import sys
import time
import traceback
from lxml import etree
from selenium.webdriver import Keys
from dbse.mysql.db_mysql_insert import getDataBase
from sel.proxy.selenium_proxy_util import initSelWireChrome
from sel.proxy.selenium_proxy_util import initSelWireChromePlus
from sel.proxy.selenium_proxy_util import tab2Page
from selenium.webdriver.common.action_chains import ActionChains
from dbse.mysql.db_entity_stock_dfcf_inform import StockDfcfInform
from dbse.mysql.db_mysql_insert import addStockDfcfInform
from date.dateUtil import getDateTime
from date.dateUtil import getYear

profile = sys.argv[1:][0]
#加载chrome
browser = initSelWireChromePlus(useProxy=False,isHeadless=False,host='https://guba.eastmoney.com',useTab=False)
# 读取一个股票
browser.get('https://guba.eastmoney.com/list,300750,1,f.html')
#
print(browser.page_source)

content = browser.page_source
html = etree.fromstring(content,etree.HTMLParser())
result = html.xpath('//tbody[@class="listbody"]//tr')
db = getDataBase(profile)
add_sql = 'INSERT INTO stock_dfcf_inform (stock_code,inform_type,inform_title,inform_content,create_date) VALUES (%s,%s,%s,%s,%s)'
for index , tr in enumerate(result):
    tds = tr.getchildren()
    print(tds[2].find('div').find('a').get('title'))
    dd = tds[4].find('div').text
    print(f'{getYear()}-{dd}-00')
    entity = StockDfcfInform('300750','1',tds[2].find('div').find('a').get('title'),None,f'{getYear()}-{dd}-00')
    addStockDfcfInform(db,add_sql,entity)


#
# result2 = html.xpath('//tbody[@class="listbody"]//tr//td//div')
# print("=======================================")
# for index , tr in enumerate(result2):
#     print(tr.text)
# print(result2[0].text)
# print(result2[1].text)
# print(result2[2].text)
# print(result2[3].text)
# print(result2[4].text)
# print(result2[5].text)
# print(result2[6].text)
